/*
	DS Kanji Flash
	Copyright (C) 2009,2010 Bernhard Schelling

	This file is part of DS Kanji Flash.

	DS Kanji Flash is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	DS Kanji Flash is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with DS Kanji Flash.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _JPVOCAB_GLOBAL_
#define _JPVOCAB_GLOBAL_

#include <ulib/ulib.h>

#define VERSION_STRING "Ver 0.5"

extern UL_FONT *fntJapanese;
extern const char* kanji[];
extern bool bDrawFontShadows;

void InitTextDisplay();

#define SCN_CARD 0
#define SCN_SHOWSTROKES 1
#define SCN_DRAW 2
#define SCN_TRAIN 3
#define SCN_START 4
#define SCN_NUMOFSCENES 5

class cScene
{
protected:
	cScene(int iType);
public:
	bool WantsKeyHeldEvents, WantsKeyReleaseEvents, WantsEveryFrame;
	virtual void Enter(void *param1 = 0, void *param2 = 0, void *param3 = 0) = 0;
	virtual void ProcessInput() = 0;
	virtual void DrawScreen_Top() = 0;
	virtual void DrawScreen_Bottom() = 0;
	static void GoTo(int Type, void *param1 = 0, void *param2 = 0, void *param3 = 0);
	static cScene* Get(int Type);
};

extern cScene* pSceneCurrent;

struct sRect
{
	int x,y,w,h;
	int x2();
	int y2();
	bool inside(int tx, int ty);
	bool touchButton();
	sRect(int x,int y,int w,int h);
};

#define BUTTON_BG_RED 1
#define BUTTON_BG_GREEN 2
#define BUTTON_BG_BLUE 3
#define BUTTON_BG_WHITE 4

#define COL_BLACK RGB15(0, 0, 0)
#define COL_WHITE RGB15(31, 31, 31)
#define COL_RED RGB15(31, 0, 0)
#define COL_GREEN RGB15(0, 31, 0)
#define COL_BLUE RGB15(0, 0, 31)
#define COL_YELLOW RGB15(31, 31, 0)
#define COL_MAGENTA RGB15(0, 31, 31)

inline void ResetDoubleClick() { ul_keys.touch._clickTime = 0; }
int SetUCS(char *str, wchar_t code);
wchar_t GetUCS(const char **txt);
wchar_t GetUCS(const char *txt);
wchar_t GetKanjiUCS(int iKanji);
int GetKanjiIndex(wchar_t numChar);
int StringGetWidthOrDraw(UL_FONT* fnt, const char *str, int numchars = -1, bool draw = true, bool measure = false, int x = 0, int y = 0, UL_COLOR col = COL_WHITE);
void drawButtonBG(int x, int y, int w, int h, u8 mode, const char* str = NULL, UL_COLOR col = COL_WHITE);
void drawButtonBG(sRect &rec, u8 mode, const char* str = NULL, UL_COLOR col = COL_WHITE);

inline void displayString(UL_FONT* fnt, const char *str, int x, int y, UL_COLOR col = COL_WHITE, int numchars = -1)
{
	StringGetWidthOrDraw(fnt, str, numchars, true, false, x, y, col);
}

inline int displayStringWidth(UL_FONT* fnt, const char *str, int x, int y, UL_COLOR col = COL_WHITE, int numchars = -1)
{
	return StringGetWidthOrDraw(fnt, str, numchars, true, true, x, y, col);
}

inline int widthString(UL_FONT* fnt, const char *str, int numchars = -1)
{
	return StringGetWidthOrDraw(fnt, str, numchars, false, true);
}

inline void displayStringCenter(UL_FONT* fnt, const char *str, sRect &rec, UL_COLOR col = COL_WHITE, int numchars = -1)
{
	displayString(fnt, str, rec.x+(rec.w-widthString(fnt, str))/2, rec.y+(rec.h-fnt->charHeight)/2, col, numchars);
}

inline void displayStringCenter(UL_FONT* fnt, const char *str, int x, int y, int width, UL_COLOR col = COL_WHITE, int numchars = -1)
{
	displayString(fnt, str, x+(width-widthString(fnt, str))/2, y, col);
}

inline void displayStringRight(UL_FONT* fnt, const char *str, int x, int y, UL_COLOR col = COL_WHITE, int numchars = -1)
{
	displayString(fnt, str, x-widthString(fnt, str, numchars), y, col, numchars);
}

/*

inline void displayString(UL_FONT* fnt, const string &str, int x, int y, UL_COLOR col = COL_WHITE)
{
	StringGetWidthOrDraw(fnt, str, x, y, true, col);
}


inline void displayStringCenter(UL_FONT* fnt, const string &str, sRect &rec, UL_COLOR col = COL_WHITE)
{
	displayString(fnt, str, rec.x+(rec.w-widthString(fnt, str))/2, rec.y+(rec.h-fnt->charHeight)/2, col);
}

*/

void glDrawTriangle(int x0, int y0, int x1, int y1, int x2, int y2, UL_COLOR color);
void glDrawCircle(int x, int y, int rad, UL_COLOR colColor);
void glDrawLine(u16 x1, u16 y1, u16 x2, u16 y2, u16 tStart, u16 tEnd, UL_COLOR colStart, UL_COLOR colEnd, bool bFeather = false);
float sqrt(float number);
#define LENSIZE(x,y) (x==0&&y==0?0:sqrt((x)*(x)+(y)*(y)))
#define LEN(x1,y1,x2,y2) ((x1)-(x2)==0&&(y1)-(y2)==0?0:sqrt(((x1)-(x2))*((x1)-(x2))+((y1)-(y2))*((y1)-(y2))))

#endif //_JPVOCAB_GLOBAL_
